const path = require('path')

const config = {
  projectName: 'taro-lowcode-app',
  date: '2021-12-13',
  designWidth: 750,
  deviceRatio: {
    640: 2.34 / 2,
    750: 1,
    828: 1.81 / 2
  },
  env: {
    VUE_APP_DEFAULT_PAGE: '$DEFAULT_PAGE',
    VUE_APP_TOKEN: '$TOKEN',
    VUE_APP_HTTP_BASE_URL: '$BASE_URL',
    VUE_APP_CLIENT_ID: '$CLIENT_ID',
    VUE_APP_TARGET_FUNCTIONIDS: '$TARGET_FUNCTIONIDS',
    VUE_APP_LOCALSTORAGE_PRE: JSON.stringify('hips-lowcode'),
    VUE_APP_ACCESS_TOKEN_KEY: JSON.stringify('access-token')
  },
  sourceRoot: 'src',
  outputRoot: `dist/${process.env.TARO_ENV}`,
  plugins: ['@hips/taro-plugin-ace', '@hips/taro-plugin-dataset'],
  copy: {
    patterns: [],
    options: {}
  },
  framework: 'vue',
  alias: {
    assets: path.resolve(__dirname, '..', 'src/assets'),
    tools: path.resolve(__dirname, '..', 'src/tools'),
    request: path.resolve(__dirname, '..', 'src/request'),
    components: path.resolve(__dirname, '..', 'src/components'),
    axios: path.resolve(
      __dirname,
      '..',
      'node_modules/taro-axios/lib/index.esm.js'
    )
  },
  mini: {
    postcss: {
      pxtransform: {
        enable: true,
        config: {}
      },
      url: {
        enable: true,
        config: {
          limit: 1024 // 设定转换尺寸上限
        }
      },
      cssModules: {
        enable: true, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    }
  },
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
    postcss: {
      autoprefixer: {
        enable: true,
        config: {}
      },
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    }
  }
}

module.exports = function (merge) {
  if (process.env.APP_ENV === 'development') {
    return merge({}, config, require('./dev'))
  } else if (process.env.APP_ENV === 'testting') {
    return merge({}, config, require('./test'))
  }
  return merge({}, config, require('./prod'))
}
